/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package brasilquad.beans;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *
 * @author Fran
 */
public class ManipulaArquivo {

    public ArrayList<NoBruto> lerArquivoMapa() {

        /*******************************************/
        /** Pega o arquivo com os dados espaciais **/
        /*******************************************/
        File f = new File("BR.txt");

        /***********************************/
        /** Array List que ser? retornado **/
        /***********************************/
        ArrayList<NoBruto> listBruto = new ArrayList<NoBruto>();

        /*************************/
        /** Se o arquivo existe **/
        /*************************/
        if (f.exists()) {
            try {

                /**************************/
                /** Instancia o "Leitor" **/
                /**************************/
                BufferedReader in = new BufferedReader(new FileReader(f));

                String line;

                /*************************/
                /** Contador das Linhas **/
                /*************************/
                int lineCount = 0;

                /********************************/
                /** Enquanto existir as linhas **/
                /********************************/
                while ((line = in.readLine()) != null) {
                    
                    /********************************************************/
                    /** Divide as linhas pela tabula??o e coloca num array **/
                    /********************************************************/
                    String[] colunas = line.split("\t");

                    /*********************************************/
                    /** Coloca todas as colunas como N?s Brutos **/
                    /*********************************************/
                    NoBruto noBruto = new NoBruto();
                    noBruto.setGeonameId(colunas[0]);
                    noBruto.setFeatureClass(colunas[6]);
                    noBruto.setFeatureCode(colunas[7]);
                    noBruto.setLatitude(colunas[4]);
                    noBruto.setLongitude(colunas[5]);
                    noBruto.setPopulacao(colunas[14]);
                    noBruto.setPosicaoArq(lineCount);
                    noBruto.setCidade(colunas[2]);

                    listBruto.add(noBruto);

                    lineCount++;


                }

                /*
                 *
                 *
                 *
                NoQuad no = new NoQuad();
                no.setGeonameId(noBruto.getGeonameId());
                no.setLatitude(noBruto.getLatitude());
                no.setLongitude(noBruto.getLongitude());
                no.setPosicaoArq(noBruto.getPosicaoArq());
                 *
                 *
                 *
                 **/

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return listBruto;

    }

//    public static void main(String[] args) {
//        new ManipulaArquivo().lerArquivoMapa();
//    }
}
